#include "gd32f30x.h"
#include <stdio.h>
#include <rtthread.h>
void board_init(void);
static void led_thread_init(void);
static void led_thread_entry(void);
static void dog_thread_entry(void);
int main(void)
{
    board_init();
		led_thread_init();
}
void board_init()
{
    rcu_periph_clock_enable(RCU_GPIOC);
    gpio_init(GPIOC, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ,GPIO_PIN_6);
    GPIO_BOP(GPIOC) = GPIO_PIN_6;
	  rcu_all_reset_flag_clear();
		rt_thread_t dog_task_tid = rt_thread_create("dog", dog_thread_entry, RT_NULL, 256, 2, 10); //
    rcu_periph_clock_enable(RCU_WWDGT);
    wwdgt_config(127, 100, WWDGT_CFG_PSC_DIV8);
	  wwdgt_enable();
    if (dog_task_tid != RT_NULL)
    {
        rt_thread_startup(dog_task_tid);
		}
}
static void led_thread_init(void)
{
    rt_thread_t led_task_tid = rt_thread_create("led", led_thread_entry, RT_NULL, 1024, 3, 10); //
    if (led_task_tid != RT_NULL)
    {
        rt_thread_startup(led_task_tid);
		}
}
static void led_thread_entry(void)
{
    while(1){
        GPIO_BOP(GPIOC) = GPIO_PIN_6;
        rt_thread_delay(1000);
				GPIO_BC(GPIOC) = GPIO_PIN_6;
        rt_thread_delay(1000);
    }
}
static void dog_thread_entry(void)
{
    while(1){
        rt_thread_delay(30);
        wwdgt_counter_update(127);
    }
}